/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.xyplot.xyplot_view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.plaf.FontUIResource;

import br.ufmg.dees.insane.commons.InsaneProperties;
import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.commons.command.CommandHolder;
import br.ufmg.dees.insane.commons.view.ImageDA;

/**
 * @author  Samuel Silva Penna
 */
public class DesktopXYPlot extends JFrame implements ActionListener {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
 
    private InsaneProperties  properties = new InsaneProperties();
	
	//Main DESKTOP
	private JDesktopPane desktop = new JDesktopPane();
    
	
//*****************************************************************************

	/**
	 * The constructor method. <br>
	 * Calls the init() method throwing an exception.
	 */
	public DesktopXYPlot() {
	    try {
            this.setFonts();
	        init();
	    } catch (Exception e) {
	        e.printStackTrace();
	    }
	}

//*****************************************************************************

	/**
	 *  It's called by the constructor. <br>
	 *  Sets Panels, components and provides a window listener.
	 */
	private void init() throws Exception {
			
        this.setTitle("INSANE XYPlot " + this.getProperties().getVersion());
        this.setSize(Toolkit.getDefaultToolkit().getScreenSize().width - 100, Toolkit.getDefaultToolkit().getScreenSize().height-100);
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
         
        this.setFonts();
		this.getContentPane().setLayout(new BorderLayout());
		this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		this.addWindowListener(new WindowAdapter() {
		    public void windowClosing(WindowEvent e) {
		        System.exit(JFrame.EXIT_ON_CLOSE);
		    }
		} );
		
		Image ico = Toolkit.getDefaultToolkit().getImage(ClassLoader.getSystemResource("br/ufmg/dees/insane/images/Insane64.gif"));
		this.setIconImage(ico);
		
		this.getContentPane().add(desktop);
		
		this.setFonts();		
		setInitialInterface();
		
	}
	
//******************************************************************************
	public void setFonts() {
		
		try {
            UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
			//UIManager.setLookAndFeel(UIManager.getInstalledLookAndFeels()[2].getClassName());
            Font fontCurrent = UIManager.getFont("Button.font");
            String name = fontCurrent.getName();
            
            //Creates similar font with the specified style and size
            FontUIResource fontResourceNew  = new FontUIResource(name, Font.PLAIN, 12);
            
            //Sets all items fonts
            UIManager.put("Button.font", fontResourceNew);
            UIManager.put("CheckBox.font", fontResourceNew);
            UIManager.put("CheckBoxMenuItem.font", fontResourceNew);
            UIManager.put("ColorChooser.font", fontResourceNew);
            UIManager.put("ComboBox.font", fontResourceNew);
            UIManager.put("DesktopIcon.font", fontResourceNew);
            UIManager.put("EditorPane.font", fontResourceNew);
            UIManager.put("InternalFrame.font", fontResourceNew);
            UIManager.put("Label.font", fontResourceNew);
            UIManager.put("List.font", fontResourceNew);
            UIManager.put("MenuBar.font", fontResourceNew);
            UIManager.put("Menu.font", fontResourceNew);
            UIManager.put("MenuItem.font", fontResourceNew);
            UIManager.put("OptionPane.font", fontResourceNew);
            UIManager.put("PasswordField.font", fontResourceNew);
            UIManager.put("PopupMenu.font", fontResourceNew);
            UIManager.put("ProgressBar.font", fontResourceNew);
            UIManager.put("RadioButton.font", fontResourceNew);
            UIManager.put("RadioButtonMenuItem.font", fontResourceNew);
            UIManager.put("ScrollPane.font", fontResourceNew);
            UIManager.put("TabbedPane.font", fontResourceNew);
            UIManager.put("TableHeader.font", fontResourceNew);
            UIManager.put("TextArea.font", fontResourceNew);
            UIManager.put("TextField.font", fontResourceNew);
            UIManager.put("TextPane.font", fontResourceNew);
            UIManager.put("TitledBorder.font", fontResourceNew);
            UIManager.put("ToggleButton.font", fontResourceNew);
            UIManager.put("ToolBar.font", fontResourceNew);
            UIManager.put("ToolTip.font", fontResourceNew);
            UIManager.put("Tree.font", fontResourceNew);
            UIManager.put("Viewport.font", fontResourceNew);

        }
        catch (Exception e){}
	}
	

//******************************************************************************

	/** Sets the Model.
	*  @param mdl The Model to be set.
	*/
	public void setModel(Object mdl) {
		//this.setToGeometry();
		}
//	******************************************************************************
	/**
	 * Returns the properties.
	 * @return  The properties.
	 * @uml.property  name="properties"
	 */
	public InsaneProperties getProperties() {
		return properties;
	}
//	******************************************************************************		
	//** Sets the initial Interface. */
	public void setInitialInterface() {
	
		desktop.removeAll();
		desktop.add(new ImageDA(ClassLoader.getSystemResource("images/Insane.jpg")), BorderLayout.CENTER);
		desktop.setBackground(Color.GRAY );
		desktop.repaint();
		desktop.updateUI();
	   		
		this.repaint();
	}
//	******************************************************************************
	/** Sets the Interface to Geometry mode. */
	public void setToGeometry() {
	
	this.repaint();
	}

//	*****************************************************************************

	/** Adds a Command to the undoList.
	 * @param cmd a the desired command
	 **/
	public void addInternalFrame(JInternalFrame F) {
		
		this.repaint();
		//Container container = F.getContentPane();
		//container.add(((JComponent)((((InterfaceXYPlot)F).getView()).getDrawingArea())), BorderLayout.CENTER);
				 
		F.pack();
		F.setVisible(true);
		F.setIconifiable(true);
		F.setPreferredSize(new Dimension(desktop.getWidth(),desktop.getHeight()));
		F.setSize(new Dimension((int)(this.getWidth()),(int)(this.getHeight()-30)));
		F.setResizable(true);
		F.setMaximizable(true);
	
		desktop.add(F);
		desktop.setVisible(true);
				
		desktop.repaint();
		desktop.updateUI();
		this.setStateButtons();
		
	}
//	*****************************************************************************
	/** Adds a Command to the undoList.
	 * @param cmd a the desired command
	 **/
	public void addToUndo(Command cmd) {
		
	}

//*****************************************************************************

	/** Adds a Command to the redoList.
	 * @param cmd a the desired command
	 */
	public void addToRedo(Command cmd) {
	
	}

//*****************************************************************************

	/** Disables the redo command.*/
	public void nothingToRedo() {
		
	}

//*****************************************************************************

	/** Disables the undo command.*/
	public void nothingToUndo() {
		
	}

//*****************************************************************************

	/**
	* Sets the Status Bar coord text.
	* @param x The first "X" coordinate.
	* @param y The second "Y" coordinate.
	*/
	public void setCoord(String x, String y) {
		
	}

//*****************************************************************************

	/**
	* Sets the Status Bar message.
	* @param str The text to be shown
	*/
	public void setMessage(String str) {
	
	}

//*****************************************************************************

	/** Method which executes the desired action to each command.*/
	public void actionPerformed(ActionEvent evt) {
		CommandHolder obj = (CommandHolder)evt.getSource();
		obj.getCommand().execute();
	}

//*****************************************************************************

	/** Sets the StateButtons of this Interface. */
	public void setStateButtons() {
		
	}
	
//	*****************************************************************************
}
